home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
term
/
term34Source.lha
/
RatePanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
38KB
|
1,399 lines
/*
** RatePanel.c
**
** Editing panel for phone units configuration
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_TIME,
GAD_FIRSTUNIT,GAD_PAY1,GAD_MINUTES1,
GAD_FOLLOWINGUNITS,GAD_PAY2,GAD_MINUTES2,
GAD_LIST,
GAD_ADDTIME,GAD_ADDDATE,GAD_EDIT,
GAD_REMOVETIME,GAD_ADDDAY,GAD_CLONE,
GAD_EDITTIME,GAD_IMPORT,GAD_REMOVE };
struct DoubleInfo
{
LONG GlyphWidth,
HeaderLen;
};
STATIC struct DoubleInfo DateInfo,
TimeInfo;
STATIC struct Hook DateHook,
TimeHook;
/* ListViewRender():
*
* This callback routine is responsible for rendering
* the single listview entries.
*/
STATIC ULONG __saveds __asm
ListViewRender(register __a0 struct Hook *Hook,register __a1 struct LVDrawMsg *Msg,register __a2 struct Node *Node)
{
/* We only know how to redraw lines. */
if(Msg -> lvdm_MethodID == LV_DRAW)
{
struct RastPort *RPort = Msg -> lvdm_RastPort;
LONG Left = Msg -> lvdm_Bounds . MinX,
Top = Msg -> lvdm_Bounds . MinY,
Width = Msg -> lvdm_Bounds . MaxX - Msg -> lvdm_Bounds . MinX + 1,
Height = Msg -> lvdm_Bounds . MaxY - Msg -> lvdm_Bounds . MinY + 1,
Delta,
FgPen,BgPen,
Len,LabelLen,Template;
UBYTE *String,Header[8];
struct DoubleInfo *Info;
Info = Hook -> h_Data;
String = &Node -> ln_Name[Info -> HeaderLen];
memcpy(Header,Node -> ln_Name,Info -> HeaderLen);
Header[Info -> HeaderLen] = 0;
/* Determine the rendering pens. */
switch(Msg -> lvdm_State)
{
case LVR_SELECTEDDISABLED:
case LVR_NORMALDISABLED:
case LVR_NORMAL:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[TEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[BACKGROUNDPEN];
break;
case LVR_SELECTED:
FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLTEXTPEN];
BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLPEN];
break;
}
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + 1,Top + Height - 1);
Left += 2;
Width -= 2;
/* Set the rendering pens. */
SetDrMd(RPort,JAM2);
SetBPen(RPort,BgPen);
Template = Info -> HeaderLen * Info -> GlyphWidth;
/* Determine header length. */
Len = TextLength(RPort,Header,Info -> HeaderLen);
/* Fill the space to precede the header. */
if((Delta = Template - Len) > 0)
{
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Delta - 1,Top + Height - 1);
}
/* Render the header, right-justified. */
SetAPen(RPort,FgPen);
Move(RPort,Left + Delta,Top + RPort -> Font -> tf_Baseline);
Text(RPort,Header,Info -> HeaderLen);
/* Adjust width and area left edge. */
Left += Template;
Width -= Template;
/* Determine length of vanilla name. */
LabelLen = strlen(String);
/* Try to make it fit. */
while(LabelLen > 0 && (Len = TextLength(RPort,String,LabelLen)) > Width)
LabelLen--;
/* Print the vanilla name if possible. */
if(LabelLen)
{
Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
Text(RPort,String,LabelLen);
Left += Len;
Width -= Len;
}
/* Fill the area to follow the vanilla name. */
if(Width > 0)
{
SetAPen(RPort,BgPen);
RectFill(RPort,Left,Top,Left + Width - 1,Top + Height - 1);
}
/* If the item happens to be disabled, draw the cross-hatch
* pattern across it.
*/
if(Msg -> lvdm_State == LVR_SELECTEDDISABLED || Msg -> lvdm_State == LVR_NORMALDISABLED)
{
SetDrMd(RPort,JAM1);
SetAPen(RPort,Msg -> lvdm_DrawInfo -> dri_Pens[BLOCKPEN]);
SetAfPt(RPort,(UWORD *)&Ghosting,1);
RectFill(RPort,Msg -> lvdm_Bounds . MinX,Msg -> lvdm_Bounds . MinY,Msg -> lvdm_Bounds . MaxX,Msg -> lvdm_Bounds . MaxY);
SetAfPt(RPort,NULL,0);
}
return(LVCB_OK);
}
else
return(LVCB_UNKNOWN);
}
STATIC struct Gadget *
CreateAllGadgets(struct PhoneEntry *Entry,struct Gadget **GadgetArray,struct Gadget **GadgetList)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_TIME_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_ABOVE|NG_HIGHLABEL;
TimeInfo . GlyphWidth = SZ_GetNumericLen("1");
TimeInfo . HeaderLen = 2;
TimeHook . h_Entry = (LONG (*)())ListViewRender;
TimeHook . h_Data = &TimeInfo;
GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_Lines, 7,
SZ_Chars, 5,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, TRUE,
GTLV_CallBack, &TimeHook,
GTLV_ShowSelected, NULL,
TAG_DONE);
SZ_SetWidth(SZ_Width(STRING_KIND,NULL,10,NULL));
SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_RATEPANEL_PAY_PER_UNIT_GAD,MSG_RATEPANEL_FOLLOWING_UNITS_GAD));
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_FIRST_UNIT_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL;
GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_NewColumn, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = SmallCurrency();
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTIN_MaxChars, 8,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_SECONDS_PER_UNIT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTIN_MaxChars, 8,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_FOLLOWING_UNITS_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL;
GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = SmallCurrency();
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTIN_MaxChars, 8,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_SECONDS_PER_UNIT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTIN_MaxChars, 8,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_DAYS_AND_DATES_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_ABOVE|NG_HIGHLABEL;
DateInfo . GlyphWidth = SZ_GetLen("1");
DateInfo . HeaderLen = 7;
DateHook . h_Entry = (LONG (*)())ListViewRender;
DateHook . h_Data = &DateInfo;
GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_NewColumn, TRUE,
SZ_Lines, 7,
SZ_Chars, 30,
GTLV_CallBack, &DateHook,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_ShowSelected, NULL,
TAG_DONE);
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_TIME_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_REMOVE_TIME_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_EDIT_TIME_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_DATE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_DAYS_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_IMPORT_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_EDIT_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_CLONE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_REMOVE_GAD),0,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_ADD_TIME_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_IN;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignBottom, TRUE,
SZ_GroupCount, 3,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_ADD_DATE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_EDIT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_REMOVE_TIME_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_GroupCount, 3,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_ADD_DAYS_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_CLONE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_EDIT_TIME_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_GroupCount, 3,
GA_Disabled, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_RATEPANEL_IMPORT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
GA_Disabled, NumPhoneEntries < 2,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_REMOVE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_GroupNext, TRUE,
GA_Disabled, TRUE,
TAG_DONE);
}
return(Gadget);
}
STATIC VOID __regargs
DisableGadgets(struct Gadget **GadgetArray,struct Window *PanelWindow,BYTE Mode)
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, Mode,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
GA_Disabled, Mode,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
GA_Disabled, Mode,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
GA_Disabled, Mode,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
GA_Disabled, Mode,
TAG_DONE);
if(Mode)
ActiveGadget = NULL;
}
STATIC struct Node * __regargs
GetNode(struct List *List,LONG Offset)
{
struct Node *Node;
LONG i;
Node = (struct Node *)List -> lh_Head;
for(i = 0 ; i < Offset ; i++)
{
if(!Node -> ln_Succ -> ln_Succ)
return(NULL);
Node = Node -> ln_Succ;
}
return(Node);
}
BYTE
RatePanel(struct List *PhoneList,struct PhoneEntry *Entry)
{
struct Window *PanelWindow;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_REMOVE + 1];
BYTE MadeChanges = FALSE;
if(CreateAllGadgets(Entry,GadgetArray,&GadgetList))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
WA_Top, GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight()) / 2,
WA_Width, SZ_GetWindowWidth(),
WA_Height, SZ_GetWindowHeight(),
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Window -> WScreen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_VANILLAKEY | BUTTONIDCMP | INTEGERIDCMP | LISTVIEWIDCMP,
WA_Title, LocaleString(MSG_RATEPANEL_RATES_PREFERENCES_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG IClass,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
LONG Selected = ~0,Count = 0,TimeSelected = ~0;
struct TimeDateNode *TimeDateNode,*NewNode;
struct List *TimeList = NULL;
GuideContext(CONTEXT_RATES);
TimeDateNode = (struct TimeDateNode *)Entry -> TimeDateList . mlh_Head;
while(TimeDateNode -> VanillaNode . ln_Succ)
{
Count++;
TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
}
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
ActiveGadget = NULL;
ClrSignal(SIG_BREAK);
while(!Terminated)
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
break;
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
IClass = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
KeySelect(GadgetArray,GAD_REMOVE,Code,PanelWindow,&Gadget,&IClass,&Code);
if(IClass == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
ActiveGadget = Gadget;
}
if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(IClass == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(IClass == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_TIME:
TimeSelected = Code;
if(Selected != ~0)
{
GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
TAG_DONE);
}
break;
case GAD_EDITTIME:
if(Selected != ~0 && TimeSelected != ~0)
{
UBYTE Time = TimeDateNode -> Table[TimeSelected] . Time;
BlockWindow(PanelWindow);
if(TimePanel(&TimeDateNode -> Table[TimeSelected] . Time))
{
struct List *NewTimeList;
MadeChanges = TRUE;
SortTimeTable(TimeDateNode);
if(NewTimeList = BuildTimeList(TimeDateNode))
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
if(TimeList)
FreeVec(TimeList);
TimeList = NewTimeList;
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, 0,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
else
{
TimeDateNode -> Table[TimeSelected] . Time = Time;
SortTimeTable(TimeDateNode);
DisplayBeep(PanelWindow -> WScreen);
}
}
ReleaseWindow(PanelWindow);
}
break;
case GAD_REMOVETIME:
if(Selected != ~0 && TimeSelected != ~0)
{
MadeChanges = TRUE;
BlockWindow(PanelWindow);
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
if(DeleteTimeDateNode(TimeDateNode,TimeSelected))
{
if(TimeList)
FreeVec(TimeList);
if(TimeList = BuildTimeList(TimeDateNode))
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, 0,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, &EmptyList,
TAG_DONE);
DisplayBeep(PanelWindow -> WScreen);
}
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, TimeSelected,
TAG_DONE);
DisplayBeep(PanelWindow -> WScreen);
}
ReleaseWindow(PanelWindow);
}
break;
case GAD_ADDTIME:
if(Selected != ~0)
{
UBYTE Time = DT_GET_TIME(12,0);
MadeChanges = TRUE;
BlockWindow(PanelWindow);
if(TimePanel(&Time))
{
BYTE AddIt = TRUE;
LONG i;
for(i = 0 ; i < TimeDateNode -> Table[0] . Count ; i++)
{
if(Time == TimeDateNode -> Table[i] . Time)
{
AddIt = FALSE;
break;
}
}
if(AddIt)
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
if(ResizeTimeDateNode(TimeDateNode,TimeDateNode -> Table[0] . Count + 1,Time))
{
SortTimeTable(TimeDateNode);
if(TimeList)
FreeVec(TimeList);
if(TimeList = BuildTimeList(TimeDateNode))
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, 0,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, &EmptyList,
TAG_DONE);
DisplayBeep(PanelWindow -> WScreen);
}
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, TimeSelected,
TAG_DONE);
DisplayBeep(PanelWindow -> WScreen);
}
}
}
ReleaseWindow(PanelWindow);
}
break;
case GAD_PAY1:
TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT] = SZ_GetInteger(Gadget);
MadeChanges = TRUE;
break;
case GAD_PAY2:
TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT] = SZ_GetInteger(Gadget);
MadeChanges = TRUE;
break;
case GAD_MINUTES1:
TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT] = SZ_GetInteger(Gadget);
MadeChanges = TRUE;
break;
case GAD_MINUTES2:
TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT] = SZ_GetInteger(Gadget);
MadeChanges = TRUE;
break;
case GAD_LIST:
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels,~0,
TAG_DONE);
if(TimeList)
FreeVec(TimeList);
TimeDateNode = (struct TimeDateNode *)GetNode((struct List *)&Entry -> TimeDateList,Code);
if(TimeList = BuildTimeList(TimeDateNode))
{
TimeSelected = 0;
Selected = Code;
DisableGadgets(GadgetArray,PanelWindow,FALSE);
TimeDateNode = (struct TimeDateNode *)GetNode((struct List *)&Entry -> TimeDateList,Selected);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, 0,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TimeDateNode -> Table[0] . Count < 2,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
if(Selected)
{
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
}
else
{
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
}
else
{
TimeDateNode = NULL;
DisplayBeep(PanelWindow -> WScreen);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, &EmptyList,
GTLV_Selected, ~0,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, TRUE,
TAG_DONE);
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
break;
case GAD_IMPORT:
BlockWindow(PanelWindow);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
MadeChanges |= ImportPanel(Entry,PhoneList);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
GTLV_Selected, 0,
TAG_DONE);
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
ReleaseWindow(PanelWindow);
break;
case GAD_ADDDAY:
case GAD_ADDDATE:
BlockWindow(PanelWindow);
MadeChanges = TRUE;
if(NewNode = CreateTimeDateNode(0,1,"",2))
{
APTR OldActiveGadget = ActiveGadget;
BYTE Result;
if(Gadget -> GadgetID == GAD_ADDDAY)
{
NewNode -> Header . Month = -1;
NewNode -> Header . Day = 0;
Result = DayPanel(NewNode);
}
else
Result = DatePanel(NewNode);
if(Result)
{
AdaptTimeDateNode(NewNode);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
AddTail((struct List *)&Entry -> TimeDateList,&NewNode -> VanillaNode);
Selected = Count++;
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, Selected,
GTLV_Top, Selected,
GTLV_MakeVisible, Selected,
TAG_DONE);
TimeDateNode = NewNode;
Redisplay: if(TimeList)
FreeVec(TimeList);
if(TimeList = BuildTimeList(TimeDateNode))
{
if(TimeSelected == ~0)
TimeSelected = 0;
DisableGadgets(GadgetArray,PanelWindow,FALSE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
GTIN_Number, TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GTLV_Labels, TimeList,
GTLV_Selected, TimeSelected,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TimeDateNode -> Table[0] . Count < 2,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, FALSE,
TAG_DONE);
ActivateGadget(GadgetArray[GAD_PAY1],PanelWindow,NULL);
ActiveGadget = GadgetArray[GAD_PAY1];
}
else
{
TimeDateNode = NULL;
DisplayBeep(PanelWindow -> WScreen);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
Selected = ~0;
ActiveGadget = NULL;
GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled, FALSE,
GTLV_Selected, 0,
TAG_DONE);
TimeSelected = ~0;
GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
}
}
else
{
FreeVec(NewNode);
if(ActiveGadget = OldActiveGadget)
ActivateGadget(OldActiveGadget,PanelWindow,NULL);
}
}
ReleaseWindow(PanelWindow);
break;
case GAD_REMOVE:
if(--Count)
{
if(TimeDateNode -> VanillaNode . ln_Succ -> ln_Succ)
NewNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
else
NewNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Pred;
}
MadeChanges = TRUE;
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
Remove(TimeDateNode);
FreeVec(TimeDateNode);
if(Count > 1)
{
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, Count,
TAG_DONE);
TimeDateNode = NewNode;
goto Redisplay;
}
else
{
DisableGadgets(GadgetArray,PanelWindow,TRUE);
GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
GA_Disabled, TRUE,
TAG_DONE);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, ~0,
TAG_DONE);
ActiveGadget = NULL;
TimeDateNode = NULL;
}
break;
case GAD_CLONE:
if(NewNode = CreateTimeDateNode(0,1,"",TimeDateNode -> Table[0] . Count))
{
MadeChanges = TRUE;
CopyMem(TimeDateNode,NewNode,sizeof(struct TimeDateNode));
NewNode -> VanillaNode . ln_Name = NewNode -> Buffer;
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
AddTail((struct List *)&Entry -> TimeDateList,&NewNode -> VanillaNode);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, Count++,
TAG_DONE);
TimeDateNode = NewNode;
goto Redisplay;
}
break;
case GAD_EDIT:
BlockWindow(PanelWindow);
{
struct Gadget *OldActiveGadget = ActiveGadget;
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, ~0,
TAG_DONE);
if(TimeDateNode -> Header . Month == -1)
MadeChanges |= DayPanel(TimeDateNode);
else
MadeChanges |= DatePanel(TimeDateNode);
AdaptTimeDateNode(TimeDateNode);
GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
GTLV_Labels, &Entry -> TimeDateList,
GTLV_Selected, Selected,
TAG_DONE);
if(ActiveGadget = OldActiveGadget)
ActivateGadget(OldActiveGadget,PanelWindow,NULL);
}
ReleaseWindow(PanelWindow);
break;
}
}
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
if(TimeList)
FreeVec(TimeList);
}
FreeGadgets(GadgetList);
}
ActiveGadget = NULL;
return(MadeChanges);
}